/*
day307 
2020.6.30 
*/
#include<iostream>
#include<vector>
using namespace std;

class Solution {
public:
    vector<vector<int>> imageSmoother(vector<vector<int>>& M) {
		vector<vector<int>> res=M;
		
		vector<vector<int>> directions={
			{-1,-1},{-1,0},{-1,1},
			{0,-1},{0,0},{0,1},
			{1,-1},{1,0},{1,1}
		};
		
		int row_size=M.size(),col_size=M.front().size();
		for(int i=0;i<row_size;++i)
		{
			for(int j=0;j<col_size;++j)
			{
				int sum=0,count=0;
				for(int p=0;p<directions.size();++p)
				{ 
					int row=i+directions[p][0];
					int col=j+directions[p][1];
					if(row<row_size && row>=0 && col<col_size && col>=0)
					{
						sum+=M[row][col];
						count++;
					}
				}
				res[i][j]=sum/count;
			}
		}
		return res;
    }
};

int main()
{
	return 0;
 } 
